<template>
    <div></div>
</template>

<script lang="ts" setup>
import {Client} from "stompjs";
import {onMounted, onUnmounted, reactive} from "vue";

interface State {
    socket?: WebSocket,
    stompClient?: Client,
    dataList: any [],
    lastData?: {
        level: any,
        timestamp: any,
        threadName: any,
        className: any,
        body: any,
    },
    isLocked: boolean
}

const state = reactive<State>({
    dataList: [],
    isLocked: false,
});

function initWebSocket() {
    if ("WebSocket" in window) {
        const headers = {
            Authorization: "Bearer " + window.localStorage.getItem("token"),
        };
        const url = "/api/websocket"; // 改成自己的服务端地址

    } else {
        alert("当前浏览器 Not support websocket");
    }
}

function closeSocket() {
    if (state.stompClient) {

    }
}

onMounted(() => {
    initWebSocket();
});

onUnmounted(() => {
    closeSocket();
});
</script>

<style lang="scss" scoped>

</style>
